package com.cuitrip.business.order.detail.orderstatus;

import android.text.TextUtils;

import com.cuitrip.business.order.detail.OrderMode;
import com.cuitrip.business.order.detail.ui.IOrderDetailView;
import com.cuitrip.business.order.detail.ui.model.OrderCancelReasonRenderData;
import com.cuitrip.business.order.detail.ui.model.OrderInfoPartRenderData;
import com.cuitrip.business.order.detail.ui.model.PricePartRenderData;
import com.cuitrip.business.order.detail.ui.model.SimpleServicePartRenderData;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.presenter.CommentPartRenderData;
import com.cuitrip.service.R;
import com.cuitrip.util.PlatformUtil;

/**
 * Created by baziii on 15/8/12.
 */
public abstract class BaseOrderFormPresent<T extends IOrderDetailView> extends IOrderFormPresent<T> {

    public BaseOrderFormPresent(T orderDetailView) {
        super(orderDetailView);
    }

    public BaseOrderFormPresent(T orderDetailView, OrderItem orderItem) {
        super(orderDetailView);
        setOrderItem(orderItem);
    }


    public OrderMode build(OrderItem orderItem) {
        SimpleServicePartRenderData servicePartRenderData = buildServiceData(orderItem);
        OrderMode result = new OrderMode(servicePartRenderData,
                buildCommentData(orderItem),
                buildOrderInfoData(orderItem), buildPriceInfoData(orderItem),buildOrderCancelReasonData(orderItem), getBottomText(orderItem), getBottomActionText(orderItem), getBottomButtonStyle(orderItem));
        return result;
    }


    public OrderCancelReasonRenderData buildOrderCancelReasonData(OrderItem orderItem) {
        return null;
    }

    public CommentPartRenderData buildCommentData(OrderItem orderItem) {
        return null;
    }

    public OrderInfoPartRenderData buildOrderInfoData(OrderItem orderItem) {
        OrderInfoPartRenderData renderData = new OrderInfoPartRenderData(orderItem.getServiceDate(), orderItem.getBuyerNum(), orderItem.getServiceTime());
        return renderData;
    }

    public PricePartRenderData buildPriceInfoData(OrderItem orderItem) {
        PricePartRenderData renderData = copyFromOrderItem(orderItem);
        renderData.setPriceMode(PricePartRenderData.PriceMode.Simple);
        return renderData;
    }

    protected PricePartRenderData copyFromOrderItem(OrderItem orderItem){
        PricePartRenderData renderData = new PricePartRenderData(orderItem.getOrderPrice(), orderItem.getShowPrice(),
                orderItem.getTransactionFee(), orderItem.getPlatformFee(), orderItem.getCouponFee(),
                orderItem.getRefundFee(), orderItem.getCancellationFee(), orderItem.getPayCurrency(), orderItem.getPriceType(),orderItem.getServiceFeeIsCharged(),orderItem.getTranFeeIsCharged());
        return renderData;
    }

    public enum BottomButtonStyle{
        NONE ,WHITE, ORANGE
    }


    public abstract String getBottomActionText(OrderItem orderItem);

    public abstract String getBottomText(OrderItem orderItem);

    public abstract BottomButtonStyle getBottomButtonStyle(OrderItem orderItem);

    public SimpleServicePartRenderData buildServiceData(OrderItem orderItem) {
        return SimpleServicePartRenderData.getInstance(orderItem);
    }

    protected String getUnvaliableReason(OrderItem orderItem) {
        if (TextUtils.isEmpty(orderItem.getInvalidReason())) {
            return PlatformUtil.getInstance().getString(R.string.feedback_no_data);
        }
        return orderItem.getInvalidReason();
    }


}
